package com.eureka.eurekaserviceinvoker.controller;

import com.eureka.eurekaserviceinvoker.client.HelloClient;
import com.eureka.eurekaserviceinvoker.entity.Person;
import com.eureka.eurekaserviceinvoker.service.CollapserService;
import com.eureka.eurekaserviceinvoker.service.PersonDefaultService;
import com.eureka.eurekaserviceinvoker.service.PersonService;
import com.netflix.hystrix.HystrixCircuitBreaker;
import com.netflix.hystrix.HystrixCommandKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.stream.IntStream;

/**
 *
 * Created by earl on 2018/4/17.
 */
@RestController
@RequestMapping("/feign")
public class FeignController {

    @Autowired
    private HelloClient helloClient;

    //测试hystrix与feign整合
    @GetMapping("/hello")
    public String hello( ){
        String helloResult = helloClient.hello();
        // 获取断路器,对应application.yml属性hystrix.command....
        HystrixCircuitBreaker breaker = HystrixCircuitBreaker.Factory
                .getInstance(HystrixCommandKey.Factory
                        .asKey("HelloClient#hello()"));
        System.out.println("断路器状态： "+breaker.isOpen());
        return helloResult;
    }

    //测试hystrix与feign整合,fallBack方法(必须application.yml属性feign.hystrix.enable)
    @GetMapping("/hello2")
    public String hello2( ){
        String helloResult = helloClient.hello2();
        return helloResult;
    }



}
